package com.midea.ai.air.ui.home.fragment;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.ListView;

import com.midea.ai.air.R;
import com.midea.ai.air.common.BaseFragment;
import com.midea.ai.air.common.ConsVal;
import com.midea.ai.air.common.Global;
import com.midea.ai.air.ui.home.adapter.EditRoomSceneAdapter;
import com.midea.ai.air.ui.home.data.SceneModel;
import com.midea.ai.air.utils.JumpUtils;

/**
 * Created by ouyangdi on 2016/4/8.
 * 编辑房间->情景Fragment
 */
public class EditRoomSceneFragment extends BaseFragment {
    private ListView mSceneList;
    private EditRoomSceneAdapter mRoomSceneAdapter;
    private ImageView mIvAllCloseSwitch;
    private boolean mIsSceneOn = false;
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_edit_room_scene, container, false);
        initData();
        initViews(view);
        return view;
    }

    private void initData() {
        mRoomSceneAdapter = new EditRoomSceneAdapter(getActivity(), 0, Global.mScenes);
    }
    private void initViews(View view) {
        mSceneList = (ListView)view.findViewById(R.id.list_scenes);
        mSceneList.setAdapter(mRoomSceneAdapter);
        mSceneList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                SceneModel item=(SceneModel)parent.getAdapter().getItem(position);
                JumpUtils.toPage(getActivity(), item.getStrScene(), getResources().getString(R.string.air_home_edit_room_scene), ConsVal.ACTIVITY_TAG_EDIT_ROOM_SET_SCENE_SET);
            }
        });

        mIvAllCloseSwitch = (ImageView)view.findViewById(R.id.all_device_switch);
        mIvAllCloseSwitch.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(mIsSceneOn) {
                    mIvAllCloseSwitch.setImageResource(R.drawable.more_setting_location_bt_off);
                    mIsSceneOn = false;
                    return;
                }
                mIvAllCloseSwitch.setImageResource(R.drawable.more_setting_location_bt_on);
                mIsSceneOn = true;
            }
        });
    }


}
